﻿<div bsModal #editModal="bs-modal" (onShown)="onShown()" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="editModal"
     aria-hidden="true" [config]="{backdrop: 'static'}">
    <div class="modal-dialog">

        <div class="modal-content">

            <form #tenantEditForm="ngForm" role="form" novalidate class="form-validation" (submit)="save()" *ngIf="tenant && active">
                <div class="modal-header">
                    <h4 class="modal-title">
                        <span>{{l("EditTenant")}}: {{tenant.tenancyName}}</span>
                    </h4>
                </div>
                <div class="modal-body">

                    <div class="form-group form-md-line-input form-md-floating-label no-hint">
                        <input #nameInput type="text" name="Name" class="form-control input-ltr" [ngClass]="{'edited':tenant.name}" [(ngModel)]="tenant.name" required maxlength="128">
                        <label>{{l("Name")}}</label>
                    </div>

                    <div class="form-group form-md-line-input form-md-floating-label no-hint" *ngIf="currentConnectionString">
                        <input type="text" name="ConnectionString" class="form-control edited" [(ngModel)]="tenant.connectionString" required maxlength="1024">
                        <label>{{l("DatabaseConnectionString")}}</label>
                    </div>

                    <div *ngIf="currentConnectionString">
                        <span class="help-block text-warning">{{l("TenantDatabaseConnectionStringChangeWarningMessage")}}</span>
                    </div>

                    <div class="form-group form-md-line-input form-md-floating-label has-info">
                        <select id="edition" name="edition" class="form-control edited" [(ngModel)]="tenant.editionId" (change)="onEditionChange($event)">
                            <option *ngFor="let edition of editions" [value]="edition.value">{{edition.displayText}}</option>
                        </select>
                        <label for="edition">{{l("Edition")}}</label>
                    </div>

                    <div [hidden]="!isSubscriptionFieldsVisible" class="md-checkbox-list">
                        <div class="md-checkbox">
                            <input id="CreateTenant_IsUnlimited" class="md-check" type="checkbox" name="IsUnlimited" [(ngModel)]="isUnlimited" (ngModelChange)="onUnlimitedChange()"/>
                            <label for="CreateTenant_IsUnlimited">
                                <span class="inc"></span>
                                <span class="check"></span>
                                <span class="box"></span>
                                {{l("UnlimitedTimeSubscription")}}
                            </label>
                        </div>
                    </div>
                    <div [hidden]="isUnlimited || !isSubscriptionFieldsVisible" class="form-group form-md-line-input form-md-floating-label" [ngClass]="{'has-error': !subscriptionEndDateUtcIsValid }">
                        <input type="datetime" #SubscriptionEndDateUtc name="SubscriptionEndDateUtc" class="form-control"
                               [ngClass]="{'edited':tenant.subscriptionEndDateUtc}"
                               [value]="formatSubscriptionEndDate(tenant.subscriptionEndDateUtc)"
                               [required]="!isUnlimited">
                        <label>{{l("SubscriptionEndDateUtc")}}</label>
                    </div>

                    <div [hidden]="!isSubscriptionFieldsVisible" class="md-checkbox-list">
                        <div class="md-checkbox">
                            <input id="CreateTenant_IsInTrialPeriod" class="md-check" type="checkbox" name="IsInTrialPeriod" [disabled]="selectedEditionIsFree()" [(ngModel)]="tenant.isInTrialPeriod">
                            <label for="CreateTenant_IsInTrialPeriod">
                                <span class="inc"></span>
                                <span class="check"></span>
                                <span class="box"></span>
                                {{l("IsInTrialPeriod")}}
                            </label>
                        </div>

                        <div class="alert alert-warning" *ngIf="selectedEditionIsFree()">
                            {{l("FreeEditionsCannotHaveTrialVersions")}}
                        </div>
                    </div>

                    <div class="md-checkbox-list">

                        <div class="md-checkbox">
                            <input id="EditTenant_IsActive" class="md-check" type="checkbox" name="IsActive" [(ngModel)]="tenant.isActive">
                            <label for="EditTenant_IsActive">
                                <span class="inc"></span>
                                <span class="check"></span>
                                <span class="box"></span>
                                {{l("Active")}}
                            </label>
                        </div>
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" [disabled]="saving" class="btn btn-default" (click)="close()">{{l("Cancel")}}</button>
                    <button type="submit" [buttonBusy]="saving" [busyText]="l('SavingWithThreeDot')" class="btn btn-primary blue" [disabled]="!tenantEditForm.form.valid || saving || !subscriptionEndDateUtcIsValid"><i class="fa fa-save"></i> <span>{{l("Save")}}</span></button>
                </div>
            </form>

        </div>
    </div>
</div>
